<html>
<!-- Mirrored from infohost.nmt.edu/tcc/help/pubs/tkinter/web/text-methods.html by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 06 Nov 2017 11:41:53 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8" /><!-- /Added by HTTrack -->
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>24.8. Methods on Text widgets</title><link rel="stylesheet" href="css/docbook.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.70.1"><link rel="start" href="index.html" title="Tkinter 8.5 reference: a GUI for Python"><link rel="up" href="text.html" title="24. The Text widget"><link rel="prev" href="text-undo-stack.html" title="24.7. The Text widget undo/redo
      stack"><link rel="next" href="toplevel.html" title="25. Toplevel: Top-level window
      methods"></head><body><div class="topnavbar"><a href="toplevel.html">Next</a> / <a href="text-undo-stack.html">Previous</a> / <a href="index.html">Contents</a></div><div class="navheader"><table width="100%" summary="Navigation header"><tr valign="top"><td align="left" valign="top"><h1><span class="application">Tkinter</span> 8.5 reference: a GUI for Python</h1></td><td><img alt="organizational logo" src="img/logo.png"></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="text-methods"></a>24.8. Methods on <code class="code">Text</code> widgets</h3></div></div></div><p>
        These methods are available on all text widgets:
      </p><div class="variablelist"><dl><dt><span class="term">
            <code class="code">.bbox(<em class="replaceable"><code>index</code></em>)</code>
          </span></dt><dd><p>
              Returns the bounding box for the character at the
              given index, a 4-tuple <code class="code">(<em class="replaceable"><code>x</code></em>, <em class="replaceable"><code>y</code></em>,
              <em class="replaceable"><code>width</code></em>, <em class="replaceable"><code>height</code></em>)</code>.  If the character
              is not visible, returns <code class="code">None</code>.  Note
              that this method may not return an accurate value
              unless you call the <code class="code">.update_idletasks()</code> method (see <a href="universal.html" title="26. Universal widget methods">Section 26, “Universal widget methods”</a>).
            </p></dd><dt><span class="term">
            <code class="code">.compare(<em class="replaceable"><code>index1</code></em>,
            <em class="replaceable"><code>op</code></em>,
            <em class="replaceable"><code>index2</code></em>)</code>
          </span></dt><dd><p>
              Compares the positions of two indices in the
              text widget, and returns true if the relational
              <code class="code"><em class="replaceable"><code>op</code></em></code>
              holds between
              <code class="code"><em class="replaceable"><code>index1</code></em></code>
              and
              <code class="code"><em class="replaceable"><code>index2</code></em></code>.
              The
              <code class="code"><em class="replaceable"><code>op</code></em></code>
              specifies what comparison to use, one of:
              <code class="code">'&lt;'</code>,
              <code class="code">'&lt;='</code>,
              <code class="code">'=='</code>,
              <code class="code">'!='</code>,
              <code class="code">'&gt;='</code>, or
              <code class="code">'&gt;'</code>.
            </p><p>
              For example, for a text widget <code class="code">t</code>,
              <code class="code">t.compare('2.0', '&lt;=', END)</code>
              returns true if the beginning of the second line is
              before or at the end of the text in <code class="code">t</code>.
            </p></dd><dt><span class="term">
            <code class="code">.delete(<em class="replaceable"><code>index1</code></em>,
            <em class="replaceable"><code>index2</code></em>=None)</code>
          </span></dt><dd><p>
              Deletes text starting just after <code class="code"><em class="replaceable"><code>index1</code></em></code>.  If the
              second argument is omitted, only one character is
              deleted.  If a second index is given, deletion
              proceeds up to, but not including, the character
              after <code class="code"><em class="replaceable"><code>index2</code></em></code>.  Recall
              that indices sit <span class="emphasis"><em>between</em></span>
              characters.
            </p></dd><dt><span class="term">
            <code class="code">.dlineinfo(<em class="replaceable"><code>index</code></em>)</code>
          </span></dt><dd><p>
              Returns a bounding box for the line that contains
              the given <code class="code"><em class="replaceable"><code>index</code></em></code>.  For the form of the bounding box, and a
              caution about updating idle tasks, see the
              definition of the <code class="code">.bbox</code> method
              above.
            </p></dd><dt><span class="term">
            <code class="code">.edit_modified(arg=None)</code>
          </span></dt><dd><p>
              Queries, sets, or clears the <em class="firstterm">modified
              flag</em>.  This flag is used to track
              whether the contents of the widget have been
              changed.  For example, if you are implementing a
              text editor in a <code class="code">Text</code> widget, you
              might use the modified flag to determine whether
              the contents have changed since you last saved the
              contents to a file.
            </p><p>
              When called with no argument, this method returns
              <code class="code">True</code> if the modified flag has been
              set, <code class="code">False</code> if it is clear.  You can
              also explicitly set the modified flag by passing a
              <code class="code">True</code> value to this method, or clear
              it by passing a <code class="code">False</code> value.
            </p><p>
              Any operation that inserts or deletes text, whether
              by program actions or user actions, or an undo or
              redo operation, will set the modified flag.
            </p></dd><dt><span class="term">
            <code class="code">.edit_redo()</code>
          </span></dt><dd><p>
              Performs a redo operation.  For details, see <a href="text-undo-stack.html" title="24.7. The Text widget undo/redo
      stack">Section 24.7, “The <code class="code">Text</code> widget undo/redo
      stack”</a>.
            </p></dd><dt><span class="term">
            <code class="code">.edit_reset()</code>
          </span></dt><dd><p>
              Clears the undo stack.
            </p></dd><dt><span class="term">
            <code class="code">.edit_separator()</code>
          </span></dt><dd><p>
              Pushes a separator onto the undo stack.  This
              separator limits the scope of a future undo
              operation to include only the changes pushed since
              the separator was pushed.  For details, see <a href="text-undo-stack.html" title="24.7. The Text widget undo/redo
      stack">Section 24.7, “The <code class="code">Text</code> widget undo/redo
      stack”</a>.
            </p></dd><dt><span class="term">
            <code class="code">.edit_undo()</code>
          </span></dt><dd><p>
              Reverses all changes to the widget's contents made
              since the last separator was pushed on the undo
              stack, or all the way to the bottom of the stack if
              the stack contains no separators.  For details, see
              <a href="text-undo-stack.html" title="24.7. The Text widget undo/redo
      stack">Section 24.7, “The <code class="code">Text</code> widget undo/redo
      stack”</a>.  It is an error
              if the undo stack is empty.
            </p></dd><dt><span class="term">
            <code class="code">.image_create(<em class="replaceable"><code>index</code></em>[, <em class="replaceable"><code>option</code></em>=<em class="replaceable"><code>value</code></em>, ...])</code>
          </span></dt><dd><p>
              This method inserts an image into the widget.  The
              image is treated as just another character, whose
              size is the image's natural size.
            </p><p>
              The options for this method are shown in the table
              below.  You may pass either a series of <code class="code"><em class="replaceable"><code>option</code></em>=<em class="replaceable"><code>value</code></em></code> arguments, or a
              dictionary of option names and values.
            </p><div class="informaltable"><table border="1"><colgroup><col align="left"><col align="left"></colgroup><tbody><tr><td align="left"><code class="code">align</code></td><td align="left">
                      This option specifies how the image is to
                      be aligned vertically if its height is less
                      than the height of its containing line.
                      Values may be <code class="code">top</code> to align
                      it at the top of its space; <code class="code">center</code> to center it; <code class="code">bottom</code> to place it at the bottom;
                      or <code class="code">baseline</code> to line up the
                      bottom of the image with the text baseline.
                    </td></tr><tr><td align="left"><code class="code">image</code></td><td align="left">
                      The image to be used.  See <a href="images.html" title="5.9. Images">Section 5.9, “Images”</a>.
                    </td></tr><tr><td align="left"><code class="code">name</code></td><td align="left">
                      You can assign a name to this instance of
                      the image.  If you omit this option,
                      <span class="application">Tkinter</span> will generate a unique name.  If
                      you create multiple instances of an image
                      in the same <code class="code">Text</code> widget,
                      <span class="application">Tkinter</span> will generate a unique name by
                      appending a “<code class="code">#</code>” followed by a number.
                    </td></tr><tr><td align="left"><code class="code">padx</code></td><td align="left">
                      If supplied, this option is a number of
                      pixels of extra space to be added on both
                      sides of the image.
                    </td></tr><tr><td align="left"><code class="code">pady</code></td><td align="left">
                      If supplied, this option is a number of
                      pixels of extra space to be added above and
                      below the image.
                    </td></tr></tbody></table></div></dd><dt><span class="term">
            <code class="code">.get(<em class="replaceable"><code>index1</code></em>,
            <em class="replaceable"><code>index2</code></em>=None)</code>
          </span></dt><dd><p>
              Use this method to retrieve the current text from
              the widget. Retrieval starts at index <code class="code"><em class="replaceable"><code>index1</code></em></code>.  If
              the second argument is omitted, you get the
              character after <code class="code"><em class="replaceable"><code>index1</code></em></code>.  If you provide a
              second index, you get the text between those two
              indices.  Embedded images and windows (widgets) are
              ignored.  If the range includes multiple lines,
              they are separated by newline (<code class="code">'\n'</code>)
              characters.
            </p></dd><dt><span class="term">
            <code class="code">.image_cget(<em class="replaceable"><code>index</code></em>, <em class="replaceable"><code>option</code></em>)</code>
          </span></dt><dd><p>
              To retrieve the current value of an option set on
              an embedded image, call this method with an index
              pointing to the image and the name of the option.
            </p></dd><dt><span class="term">
            <code class="code">.image_configure(<em class="replaceable"><code>index</code></em>, <em class="replaceable"><code>option</code></em>, ...)</code>
          </span></dt><dd><p>
              To set one or more options on an embedded image,
              call this method with an index pointing to the
              image as the first argument, and one or more <code class="code"><em class="replaceable"><code>option</code></em>=<em class="replaceable"><code>value</code></em></code> pairs.
            </p><p>
              If you specify no options, you will get back a
              dictionary defining all the options on the image,
              and the corresponding values.
            </p></dd><dt><span class="term">
            <code class="code">.image_names()</code>
          </span></dt><dd><p>
              This method returns a tuple of the names of all the
              text widget's embedded images.
            </p></dd><dt><span class="term">
            <code class="code">.index(<em class="replaceable"><code>i</code></em>)</code>
          </span></dt><dd><p>
              For an index <code class="code"><em class="replaceable"><code>i</code></em></code>, this method
              returns the equivalent position in the form <code class="code">'<em class="replaceable"><code>line</code></em>.<em class="replaceable"><code>char</code></em>'</code>.
            </p></dd><dt><span class="term">
            <code class="code">.insert(<em class="replaceable"><code>index</code></em>,
            <em class="replaceable"><code>text</code></em>,
            <em class="replaceable"><code>tags</code></em>=None)</code>
          </span></dt><dd><p>
              Inserts the given <code class="code"><em class="replaceable"><code>text</code></em></code> at the
              given <code class="code"><em class="replaceable"><code>index</code></em></code>.
            </p><p>
              If you omit the <code class="code">tags</code> argument, the
              newly inserted text will be tagged with any tags
              that apply to the characters
              <span class="emphasis"><em>both</em></span> before and after the
              insertion point.
            </p><p>
              If you want to apply one or more tags to the text
              you are inserting, provide as a third argument a
              tuple of tag strings.  Any tags that apply to
              existing characters around the insertion point are
              ignored.  <span class="emphasis"><em>Note:</em></span> The third
              argument must be a tuple.  If you supply a list
              argument, <span class="application">Tkinter</span> will silently fail to apply the
              tags.  If you supply a string, each character will
              be treated as a tag.
            </p></dd><dt><span class="term">
            <code class="code">.mark_gravity(<em class="replaceable"><code>mark</code></em>,
            <em class="replaceable"><code>gravity</code></em>=None)</code>
          </span></dt><dd><p>
              Changes or queries the gravity of an existing mark;
              see <a href="text-mark.html" title="24.2. Text widget marks">Section 24.2, “<code class="code">Text</code> widget marks”</a>, above, for an
              explanation of gravity.
            </p><p>
              To set the gravity, pass in the name of the mark,
              followed by either <code class="code">tk.LEFT</code> or <code class="code">tk.RIGHT</code>.  To find the gravity of an existing
              mark, omit the second argument and the method returns
              <code class="code">tk.LEFT</code> or <code class="code">tk.RIGHT</code>.
            </p></dd><dt><span class="term">
            <code class="code">.mark_names()</code>
          </span></dt><dd><p>
              Returns a sequence of the names of all the marks in the
              window, including <code class="code">tk.INSERT</code> and <code class="code">tk.CURRENT</code>.
            </p></dd><dt><span class="term">
            <code class="code">.mark_next(<em class="replaceable"><code>index</code></em>)</code>
          </span></dt><dd><p>
              Returns the name of the mark following the given
              <code class="code"><em class="replaceable"><code>index</code></em></code>;
              if there are no following marks, the method returns
              an empty string.
            </p><p>
              If the <code class="code"><em class="replaceable"><code>index</code></em></code> is in numeric form, the method returns
              the first mark at that position.  If the <code class="code"><em class="replaceable"><code>index</code></em></code> is a
              mark, the method returns the next mark following
              that mark, which may be at the same numerical
              position.
            </p></dd><dt><span class="term">
            <code class="code">.mark_previous(<em class="replaceable"><code>index</code></em>)</code>
          </span></dt><dd><p>
              Returns the name of the mark preceding the given
              <code class="code"><em class="replaceable"><code>index</code></em></code>.
              If there are no preceding marks, the method returns
              an empty string.
            </p><p>
              If the <code class="code"><em class="replaceable"><code>index</code></em></code> is in numeric form, the method returns
              returns the last mark at that position.  If the
              <code class="code"><em class="replaceable"><code>index</code></em></code>
              is a mark, the method returns the preceding mark,
              which may be at the same numerical position.
            </p></dd><dt><span class="term">
            <code class="code">.mark_set(<em class="replaceable"><code>mark</code></em>,
            <em class="replaceable"><code>index</code></em>)</code>
          </span></dt><dd><p>
              If no mark with name <code class="code"><em class="replaceable"><code>mark</code></em></code> exists, one is created with
              <code class="code">tk.RIGHT</code> gravity and placed where <code class="code"><em class="replaceable"><code>index</code></em></code> points.  If
              the mark already exists, it is moved to the new
              location.
            </p><p>
              This method may change the position of the <code class="code">tk.INSERT</code> or <code class="code">tk.CURRENT</code> indices.
            </p></dd><dt><span class="term">
            <code class="code">.mark_unset(<em class="replaceable"><code>mark</code></em>)</code>
          </span></dt><dd><p>
              Removes the named mark.  This method cannot be used to
              remove the <code class="code">tk.INSERT</code> or <code class="code">tk.CURRENT</code> marks.
            </p></dd><dt><span class="term">
            <code class="code">.scan_dragto(<em class="replaceable"><code>x</code></em>,
            <em class="replaceable"><code>y</code></em>)</code>
          </span></dt><dd><p>
              See <code class="code">.scan_mark</code>, below.
            </p></dd><dt><span class="term">
            <code class="code">.scan_mark(<em class="replaceable"><code>x</code></em>,
            <em class="replaceable"><code>y</code></em>)</code>
          </span></dt><dd><p>
              This method is used to implement fast scrolling of
              a <code class="code">Text</code> widget.  Typically, a user
              presses and holds a mouse button at some position
              in the widget, and then moves the mouse in the
              desired direction, and the widget moves in that
              direction at a rate proportional to the distance
              the mouse has moved since the button was depressed.
              The motion may be any combination of vertical or
              horizontal scrolling.
            </p><p>
              To implement this feature, bind a mouse button down
              event to a handler that calls <code class="code">.scan_mark(<em class="replaceable"><code>x</code></em>,
              <em class="replaceable"><code>y</code></em>)</code>, where
              <code class="code"><em class="replaceable"><code>x</code></em></code> and
              <code class="code"><em class="replaceable"><code>y</code></em></code> are
              the current mouse position.  Then bind the <code class="code">&lt;Motion&gt;</code> event to a handler that
              calls <code class="code">.scan_dragto(<em class="replaceable"><code>x</code></em>, <em class="replaceable"><code>y</code></em>)</code>, where <code class="code"><em class="replaceable"><code>x</code></em></code> and <code class="code"><em class="replaceable"><code>y</code></em></code> are the new mouse
              position.
            </p></dd><dt><span class="term">
            <code class="code">.search(<em class="replaceable"><code>pattern</code></em>,
            <em class="replaceable"><code>index</code></em>,
            <em class="replaceable"><code>option</code></em>, ...)</code>
          </span></dt><dd><p>
              Searches for <code class="code"><em class="replaceable"><code>pattern</code></em></code> (which
              can be either a string or a regular expression) in
              the buffer starting at the given <code class="code"><em class="replaceable"><code>index</code></em></code>.  If it
              succeeds, it returns an index of the <code class="code">'<em class="replaceable"><code>line</code></em>.<em class="replaceable"><code>char</code></em>'</code> form; if it fails, it
              returns an empty string.
            </p><p>
              The allowable options for this method are:
            </p><div class="informaltable"><table border="1"><colgroup><col align="left"><col align="left"></colgroup><tbody><tr><td align="left">
                      <code class="code">backwards</code>
                    </td><td align="left">
                      Set this option to <code class="code">True</code> to
                      search backwards from the index.  Default
                      is forwards.
                    </td></tr><tr><td align="left">
                      <code class="code">count</code>
                    </td><td align="left">
                      If you set this option to an <code class="code">IntVar</code> control variable, when
                      there is a match you can retrieve the
                      length of the text that matched by using
                      the <code class="code">.get()</code> method on that
                      variable after the method returns.
                    </td></tr><tr><td align="left"><code class="code">exact</code></td><td align="left">
                      Set this option to <code class="code">True</code> to
                      search for text that exactly matches the
                      <code class="code"><em class="replaceable"><code>pattern</code></em></code>.  This is the default option.
                      Compare the <code class="code">regexp</code> option
                      below.
                    </td></tr><tr><td align="left"><code class="code">forwards</code></td><td align="left">
                      Set this option to <code class="code">True</code> to
                      search forwards from the index.  This is
                      the default option.
                    </td></tr><tr><td align="left">
                      <code class="code">regexp</code>
                    </td><td align="left">
                      Set this option to <code class="code">True</code> to
                      interpret the <code class="code"><em class="replaceable"><code>pattern</code></em></code> as a
                      Tcl-style regular expression.  The default
                      is to look for an exact match to <code class="code"><em class="replaceable"><code>pattern</code></em></code>.  Tcl regular expressions are a subset of
                      Python regular expressions, supporting
                      these features: <code class="code">. ^ [c<sub>1</sub>…] (…) * + ?
                      e<sub>1</sub>|e<sub>2</sub></code>
                    </td></tr><tr><td align="left">
                      <code class="code">nocase</code>
                    </td><td align="left">
                      Set this option to 1 to ignore case.  The
                      default is a case-sensitive search.
                    </td></tr><tr><td align="left">
                      <code class="code">stopindex</code>
                    </td><td align="left">
                      To limit the search, set this option to the
                      index beyond which the search should not
                      go.
                    </td></tr></tbody></table></div></dd><dt><span class="term">
            <code class="code">.see(<em class="replaceable"><code>index</code></em>)</code>
          </span></dt><dd><p>
              If the text containing the given index is not
              visible, scroll the text until that text is
              visible.
            </p></dd><dt><span class="term">
            <code class="code">.tag_add(<em class="replaceable"><code>tagName</code></em>,
            <em class="replaceable"><code>index1</code></em>,
            <em class="replaceable"><code>index2</code></em>=None)</code>
          </span></dt><dd><p>
              This method associates the tag named <code class="code"><em class="replaceable"><code>tagName</code></em></code> with a
              region of the contents starting just after index
              <code class="code"><em class="replaceable"><code>index1</code></em></code>
              and extending up to index <code class="code"><em class="replaceable"><code>index2</code></em></code>.  If you
              omit <code class="code"><em class="replaceable"><code>index2</code></em></code>, only the character after <code class="code"><em class="replaceable"><code>index1</code></em></code> is
              tagged.
            </p></dd><dt><span class="term">
            <code class="code">.tag_bind(<em class="replaceable"><code>tagName</code></em>,
            <em class="replaceable"><code>sequence</code></em>, <em class="replaceable"><code>func</code></em>, <em class="replaceable"><code>add</code></em>=None)</code>
          </span></dt><dd><p>
              This method binds an event to all the text tagged
              with <code class="code"><em class="replaceable"><code>tagName</code></em></code>.  See
              <a href="events.html" title="54. Events: responding to stimuli">Section 54, “Events”</a>, below, for more
              information on event bindings.
            </p><p>
              To create a new binding for tagged text, use the
              first three arguments: <code class="code"><em class="replaceable"><code>sequence</code></em></code>
              identifies the event, and <code class="code"><em class="replaceable"><code>func</code></em></code> is the
              function you want it to call when that event
              happens.
            </p><p>
              To add another binding to an existing tag, pass the
              same first three arguments and <code class="code">'+'</code>
              as the fourth argument.
            </p><p>
              To find out what bindings exist for a given
              sequence on a tag, pass only the first two
              arguments; the method returns the associated
              function.
            </p><p>
              To find all the bindings for a given tag, pass only
              the first argument; the method returns a list of
              all the tag's <code class="code"><em class="replaceable"><code>sequence</code></em></code>
              arguments.
            </p></dd><dt><span class="term">
            <code class="code">.tag_cget(<em class="replaceable"><code>tagName</code></em>,
            <em class="replaceable"><code>option</code></em>)</code>
          </span></dt><dd><p>
              Use this method to retrieve the value of the given
              <code class="code"><em class="replaceable"><code>option</code></em></code>
              for the given <code class="code"><em class="replaceable"><code>tagName</code></em></code>.
            </p></dd><dt><span class="term">
            <code class="code">.tag_config(<em class="replaceable"><code>tagName</code></em>,
            <em class="replaceable"><code>option</code></em>, ...)</code>
          </span></dt><dd><p>
              To change the value of options for the tag named
              <code class="code"><em class="replaceable"><code>tagName</code></em></code>,
              pass in one or more <code class="code"><em class="replaceable"><code>option</code></em>=<em class="replaceable"><code>value</code></em></code> pairs.
            </p><p>
              If you pass only one argument, you will get back a
              dictionary defining all the options and their
              values currently in force for the named tag.
            </p><p>
              Here are the options for tag configuration:
            </p><div class="informaltable"><table border="1"><colgroup><col align="left"><col align="left"></colgroup><tbody><tr><td align="left">
                      <code class="code">background</code>
                    </td><td align="left">
                      The background color for text with this
                      tag.  Note that you can't use <code class="code">bg</code> as an abbreviation.
                    </td></tr><tr><td align="left">
                      <code class="code">bgstipple</code>
                    </td><td align="left">
                      To make the background appear grayish, set
                      this option to one of the standard bitmap
                      names (see <a href="bitmaps.html" title="5.7. Bitmaps">Section 5.7, “Bitmaps”</a>).
                      This has no effect unless you also specify
                      a <code class="code">background</code>.
                    </td></tr><tr><td align="left">
                      <code class="code">borderwidth</code>
                    </td><td align="left">
                      Width of the border around text with this
                      tag.  Default is <code class="code">0</code>.  Note
                      that you can't use <code class="code">bd</code> as an
                      abbreviation.
                    </td></tr><tr><td align="left">
                      <code class="code">fgstipple</code>
                    </td><td align="left">
                      To make the text appear grayish, set this
                      option a <a href="bitmaps.html" title="5.7. Bitmaps">bitmap
                      name</a>.
                    </td></tr><tr><td align="left">
                      <code class="code">font</code>
                    </td><td align="left">
                      The font used to display text with this
                      tag.  See <a href="fonts.html" title="5.4. Type fonts">Section 5.4, “Type fonts”</a>.
                    </td></tr><tr><td align="left">
                      <code class="code">foreground</code>
                    </td><td align="left">
                      The color used for text with this tag.
                      Note that you can't use the <code class="code">fg</code> abbreviation here.
                    </td></tr><tr><td align="left">
                      <code class="code">justify</code>
                    </td><td align="left">
                      The <code class="code">justify</code> option set on the
                      first character of each line determines how that
                      line is justified: <code class="code">tk.LEFT</code> (the
                      default), <code class="code">tk.CENTER</code>, or <code class="code">tk.RIGHT</code>.
                    </td></tr><tr><td align="left">
                      <code class="code">lmargin1</code>
                    </td><td align="left">
                      How much to indent the first line of a
                      chunk of text that has this tag.  The
                      default is <code class="code">0</code>.  See <a href="dimensions.html" title="5.1. Dimensions">Section 5.1, “Dimensions”</a>for allowable values.
                    </td></tr><tr><td align="left">
                      <code class="code">lmargin2</code>
                    </td><td align="left">
                      How much to indent successive lines of a
                      chunk of text that has this tag.  The
                      default is <code class="code">0</code>.
                    </td></tr><tr><td align="left">
                      <code class="code">offset</code>
                    </td><td align="left">
                      How much to raise (positive values) or
                      lower (negative values) text with this tag
                      relative to the baseline.  Use this to get
                      superscripts or subscripts, for example.
                      For allowable values, see <a href="dimensions.html" title="5.1. Dimensions">Section 5.1, “Dimensions”</a>.
                    </td></tr><tr><td align="left">
                      <code class="code">overstrike</code>
                    </td><td align="left">
                      Set <code class="code">overstrike=1</code> to draw a
                      horizontal line through the center of text
                      with this tag.
                    </td></tr><tr><td align="left">
                      <code class="code">relief</code>
                    </td><td align="left">
                      Which 3-D effect to use for text with this tag.
                      The default is <code class="code">relief=tk.FLAT</code>;
                      for other possible values see <a href="relief.html" title="5.6. Relief styles">Section 5.6, “Relief styles”</a>.
                    </td></tr><tr><td align="left">
                      <code class="code">rmargin</code>
                    </td><td align="left">
                      <a href="dimensions.html" title="5.1. Dimensions">Size</a> of
                      the right margin for chunks of text with
                      this tag.  Default is <code class="code">0</code>.
                    </td></tr><tr><td align="left">
                      <code class="code">spacing1</code>
                    </td><td align="left">
                      This option specifies how much extra
                      vertical <a href="dimensions.html" title="5.1. Dimensions">space</a> is put
                      above each line of text with this tag.  If
                      a line wraps, this space is added only
                      before the first line it occupies on the
                      display.  Default is <code class="code">0</code>.
                    </td></tr><tr><td align="left">
                      <code class="code">spacing2</code>
                    </td><td align="left">
                      This option specifies how much extra
                      vertical space to add between displayed
                      lines of text with this tag when a logical
                      line wraps.  Default is <code class="code">0</code>.
                    </td></tr><tr><td align="left">
                      <code class="code">spacing3</code>
                    </td><td align="left">
                      This option specifies how much extra
                      vertical space is added below each line of
                      text with this tag.  If a line wraps, this
                      space is added only after the last line it
                      occupies on the display.  Default is <code class="code">0</code>.
                    </td></tr><tr><td align="left">
                      <code class="code">tabs</code>
                    </td><td align="left">
                      How tabs are expanded on lines with this
                      tag.  See <a href="text-tabs.html" title="24.6. Setting tabs in a Text widget">Section 24.6, “Setting tabs in a <code class="code">Text</code> widget”</a>.
                    </td></tr><tr><td align="left">
                      <code class="code">underline</code>
                    </td><td align="left">
                      Set <code class="code">underline=1</code> to underline
                      text with this tag.
                    </td></tr><tr><td align="left">
                      <code class="code">wrap</code>
                    </td><td align="left">
                      How long lines are wrapped in text with
                      this tag.  See the description of the <code class="code">wrap</code> option for text widgets,
                      above.
                    </td></tr></tbody></table></div></dd><dt><span class="term">
            <code class="code">.tag_delete(<em class="replaceable"><code>tagName</code></em>,
            ...)</code>
          </span></dt><dd><p>
              To delete one or more tags, pass their names to
              this method.  Their options and bindings go away,
              and the tags are removed from all regions of text.
            </p></dd><dt><span class="term">
            <code class="code">.tag_lower(<em class="replaceable"><code>tagName</code></em>,
            <em class="replaceable"><code>belowThis</code></em>=None)</code>
          </span></dt><dd><p>
              Use this method to change the order of tags in the
              tag stack (see <a href="text-tag.html" title="24.5. Text widget tags">Section 24.5, “<code class="code">Text</code> widget tags”</a>, above,
              for an explanation of the tag stack).  If you pass
              two arguments, the tag with name <code class="code"><em class="replaceable"><code>tagName</code></em></code> is
              moved to a position just below the tag with name
              <code class="code"><em class="replaceable"><code>belowThis</code></em></code>.  If you pass only one argument, that tag is
              moved to the bottom of the tag stack.
            </p></dd><dt><span class="term">
            <code class="code">.tag_names(<em class="replaceable"><code>index</code></em>=None)</code>
          </span></dt><dd><p>
              If you pass an index argument, this method returns
              a sequence of all the tag names that are associated
              with the character after that index.  If you pass
              no argument, you get a sequence of all the tag
              names defined in the text widget.
            </p></dd><dt><span class="term">
            <code class="code">.tag_nextrange(<em class="replaceable"><code>tagName</code></em>, <em class="replaceable"><code>index1</code></em>, <em class="replaceable"><code>index2</code></em>=None)</code>
          </span></dt><dd><p>
              This method searches a given region for places
              where a tag named <code class="code"><em class="replaceable"><code>tagName</code></em></code> starts.
              The region searched starts at index <code class="code"><em class="replaceable"><code>index1</code></em></code> and ends
              at index <code class="code"><em class="replaceable"><code>index2</code></em></code>.  If the
              <code class="code"><em class="replaceable"><code>index2</code></em></code>
              argument is omitted, the search goes all the way to
              the end of the text.
            </p><p>
              If there is a place in the given region where that
              tag starts, the method returns a sequence <code class="code">[<em class="replaceable"><code>i0</code></em>,
              <em class="replaceable"><code></code></em>i1]</code>, where <code class="code"><em class="replaceable"><code>i0</code></em></code> is the index
              of the first tagged character and <code class="code"><em class="replaceable"><code>i1</code></em></code> is the index
              of the position just after the last tagged
              character.
            </p><p>
              If no tag starts are found in the region, the
              method returns an empty string.
            </p></dd><dt><span class="term">
            <code class="code">.tag_prevrange(<em class="replaceable"><code>tagName</code></em>, <em class="replaceable"><code>index1</code></em>, <em class="replaceable"><code>index2</code></em>=None)</code>
          </span></dt><dd><p>
              This method searches a given region for places
              where a tag named <code class="code"><em class="replaceable"><code>tagName</code></em></code> starts.
              The region searched starts
              <span class="emphasis"><em>before</em></span> index <code class="code"><em class="replaceable"><code>index1</code></em></code> and ends
              at index <code class="code"><em class="replaceable"><code>index2</code></em></code>.  If the
              <code class="code"><em class="replaceable"><code>index2</code></em></code>
              argument is omitted, the search goes all the way to
              the end of the text.
            </p><p>
              The return values are as in <code class="code">.tag_nextrange()</code>.
            </p></dd><dt><span class="term">
            <code class="code">.tag_raise(<code class="code">tagName</code>,
            <em class="replaceable"><code>aboveThis</code></em>=None)</code>
          </span></dt><dd><p>
              Use this method to change the order of tags in the
              tag stack (see <a href="text-tag.html" title="24.5. Text widget tags">Section 24.5, “<code class="code">Text</code> widget tags”</a>, above,
              for an explanation of the tag stack).  If you pass
              two arguments, the tag with name <code class="code"><em class="replaceable"><code>tagName</code></em></code> is
              moved to a position just above the tag with name
              <code class="code"><em class="replaceable"><code>aboveThis</code></em></code>.  If you pass only one argument, that tag is
              moved to the top of the tag stack.
            </p></dd><dt><span class="term">
            <code class="code">.tag_ranges(<em class="replaceable"><code>tagName</code></em>)</code>
          </span></dt><dd><p>
              This method finds all the ranges of text in the
              widget that are tagged with name <code class="code"><em class="replaceable"><code>tagName</code></em></code>, and
              returns a sequence <code class="code">[<em class="replaceable"><code>s<sub>0</sub></code></em>,
              <em class="replaceable"><code>e<sub>0</sub></code></em>,
              <em class="replaceable"><code>s<sub>1</sub></code></em>,
              <em class="replaceable"><code>e<sub>1</sub></code></em>,
              …]</code>, where each <code class="code"><em class="replaceable"><code>s<sub>i</sub></code></em></code> is the index just before
              the first character of the range and <code class="code"><em class="replaceable"><code>e<sub>i</sub></code></em></code> is the index just after the
              last character of the range.
            </p></dd><dt><span class="term">
            <code class="code">.tag_remove(<em class="replaceable"><code>tagName</code></em>,
            <em class="replaceable"><code>index1</code></em>, <em class="replaceable"><code>index2</code></em>=None)</code>
          </span></dt><dd><p>
              Removes the tag named <code class="code"><em class="replaceable"><code>tagName</code></em></code> from
              all characters between <code class="code"><em class="replaceable"><code>index1</code></em></code> and
              <code class="code"><em class="replaceable"><code>index2</code></em></code>.
              If <code class="code"><em class="replaceable"><code>index2</code></em></code>
              is omitted, the tag is removed from the single
              character after <code class="code"><em class="replaceable"><code>index1</code></em></code>.
            </p></dd><dt><span class="term">
            <code class="code">.tag_unbind(<em class="replaceable"><code>tagName</code></em>,
            <em class="replaceable"><code>sequence</code></em>, <em class="replaceable"><code>funcid</code></em>=None)</code>
          </span></dt><dd><p>
              Remove the event binding for the given <code class="code"><em class="replaceable"><code>sequence</code></em></code> from
              the tag named <code class="code"><em class="replaceable"><code>tagName</code></em></code>.  If
              there are multiple handlers for this sequence and
              tag, you can remove only one handler by passing it
              as the third argument.
            </p></dd><dt><span class="term">
            <code class="code">.window_cget(<em class="replaceable"><code>index</code></em>,
            <em class="replaceable"><code>option</code></em>)</code>
          </span></dt><dd><p>
              Returns the value of the given
              <em class="replaceable"><code>option</code></em> for the embedded
              widget at the given
              <code class="code"><em class="replaceable"><code>index.</code></em></code>
            </p></dd><dt><span class="term">
            <code class="code">.window_configure(<em class="replaceable"><code>index</code></em>, <em class="replaceable"><code>option</code></em>)</code>
          </span></dt><dd><p>
              To change the value of options for embedded widget
              at the given <code class="code"><em class="replaceable"><code>index</code></em></code>, pass in
              one or more <code class="code"><em class="replaceable"><code>option</code></em>=<em class="replaceable"><code>value</code></em></code> pairs.
            </p><p>
              If you pass only one argument, you will get back a
              dictionary defining all the options and their
              values currently in force for the given widget.
            </p></dd><dt><span class="term">
            <code class="code">.window_create(<em class="replaceable"><code>index</code></em>,
            <em class="replaceable"><code>option</code></em>, ...)</code>
          </span></dt><dd><p>
              This method creates a window where a widget can be
              embedded within a text widget.  There are two ways
              to provide the embedded widget:
            </p><div class="orderedlist"><ol type="a"><li><p>
                  you can use pass the widget to the <code class="code">window</code> option in this method, or
                </p></li><li><p>
                  you can define a procedure that will create the
                  widget and pass that procedure as a callback to
                  the <code class="code">create</code> option.
                </p></li></ol></div><p>
              Options for <code class="code">.window_create()</code> are:
            </p><div class="informaltable"><table border="1"><colgroup><col align="left"><col align="left"></colgroup><tbody><tr><td align="left">
                      <code class="code">align</code>
                    </td><td align="left">
                      Specifies how to position the embedded widget
                      vertically in its line, if it isn't as tall as
                      the text on the line.  Values include: <code class="code">align=tk.CENTER</code> (the default), which
                      centers the widget vertically within the line;
                      <code class="code">align=tk.TOP</code>, which places the
                      top of the image at the top of the line; <code class="code">align=tk.BOTTOM</code>, which places the
                      bottom of the image at the bottom of the line;
                      and <code class="code">align=tk.BASELINE</code>, which
                      aligns the bottom of the image with the text
                      baseline.
                    </td></tr><tr><td align="left">
                      <code class="code">create</code>
                    </td><td align="left">
                      A procedure that will create the embedded
                      widget on demand.  This procedure takes no
                      arguments and must create the widget as a
                      child of the text widget and return the
                      widget as its result.
                    </td></tr><tr><td align="left">
                      <code class="code">padx</code>
                    </td><td align="left">
                      Extra <a href="dimensions.html" title="5.1. Dimensions">space</a> added to
                      the left and right of the widget within the
                      text line.  Default is <code class="code">0</code>.
                    </td></tr><tr><td align="left">
                      <code class="code">pady</code>
                    </td><td align="left">
                      Extra space added above and below the
                      widget within the text line.  Default is
                      <code class="code">0</code>.
                    </td></tr><tr><td align="left">
                      <code class="code">stretch</code>
                    </td><td align="left">
                      This option controls what happens when the
                      line is higher than the embedded widget.
                      Normally this option is <code class="code">0</code>,
                      meaning that the embedded widget is left at
                      its natural size.  If you set <code class="code">stretch=1</code>, the widget is stretched
                      vertically to fill the height of the line,
                      and the <code class="code">align</code> option is
                      ignored.
                    </td></tr><tr><td align="left">
                      <code class="code">window</code>
                    </td><td align="left">
                      The widget to be embedded.  This widget
                      must be a child of the text widget.
                    </td></tr></tbody></table></div></dd><dt><span class="term">
            <code class="code">.window_names()</code>
          </span></dt><dd><p>
              Returns a sequence containing the names of all
              embedded widgets.
            </p></dd><dt><span class="term">
            <code class="code">.xview(tk.MOVETO,
            <em class="replaceable"><code>fraction</code></em>)</code>
          </span></dt><dd><p>
              This method scrolls the text widget horizontally,
              and is intended for binding to the <code class="code"></code>command option of a related horizontal scrollbar.
            </p><p>
              This method can be called in two different ways.
              The first call positions the text at a value given
              by <code class="code"><em class="replaceable"><code>fraction</code></em></code>, where 0.0 moves the text to its leftmost
              position and 1.0 to its rightmost position.
            </p></dd><dt><span class="term">
            <code class="code">.xview(tk.SCROLL, <em class="replaceable"><code>n</code></em>,
            <em class="replaceable"><code>what</code></em>)</code>
          </span></dt><dd><p>
              The second call moves the text left or right: the <code class="code"><em class="replaceable"><code>what</code></em></code> argument
              specifies how much to move and can be either <code class="code">tk.UNITS</code> or <code class="code">tk.PAGES</code>, and <code class="code"><em class="replaceable"><code>n</code></em></code> tells how many
              characters or pages to move the text to the right
              relative to its image (or left, if negative).
            </p></dd><dt><span class="term">
            <code class="code">.xview_moveto(<em class="replaceable"><code>fraction</code></em>)</code>
          </span></dt><dd><p>
              This method scrolls the text in the same way as
              <code class="code">.xview(tk.MOVETO,
              <em class="replaceable"><code>fraction</code></em>)</code>.
            </p></dd><dt><span class="term"><code class="code">.xview_scroll(<em class="replaceable"><code>n</code></em>,
          <em class="replaceable"><code>what</code></em>)</code>
          </span></dt><dd><p>
              Same as <code class="code">.xview(tk.SCROLL,
              <em class="replaceable"><code>n</code></em>,
              <em class="replaceable"><code>what</code></em>)</code>.
            </p></dd><dt><span class="term">
            <code class="code">.yview(tk.MOVETO,
            <em class="replaceable"><code>fraction</code></em>)</code>
          </span></dt><dd><p>
              The vertical scrolling equivalent of <code class="code">.xview(tk.MOVETO,…)</code>.
            </p></dd><dt><span class="term">
            <code class="code">.yview(tk.SCROLL, <em class="replaceable"><code>n</code></em>,
            <em class="replaceable"><code>what</code></em>)</code>
          </span></dt><dd><p>
              The vertical scrolling equivalent of <code class="code">.xview(tk.SCROLL,…)</code>.  When scrolling
              vertically by <code class="code">tk.UNITS</code>, the units are
              lines.
            </p></dd><dt><span class="term">
            <code class="code">.yview_moveto(<em class="replaceable"><code>fraction</code></em>)</code>
          </span></dt><dd><p>
              The vertical scrolling equivalent of
              <code class="code">.xview_moveto()</code>.
            </p></dd><dt><span class="term">
            <code class="code">.yview_scroll(<em class="replaceable"><code>n</code></em>,
            <em class="replaceable"><code>what</code></em>)</code>
          </span></dt><dd><p>
              The vertical scrolling equivalent of <code class="code">.xview_scroll()</code>.
            </p></dd></dl></div></div><hr><div class="navfooter"><div class="botlinks"><div class="bot-next"><b>Next: </b><a href="toplevel.html">25. <code class="code">Toplevel</code>: Top-level window
      methods</a></div><div class="bot-contents"><b>Contents: </b><a href="index.html"><span class="application">Tkinter</span> 8.5 reference: a GUI for Python</a></div><div class="bot-prev"><b>Previous: </b><a href="text-undo-stack.html">24.7. The <code class="code">Text</code> widget undo/redo
      stack</a></div><div><b>Home: </b><a href="http://www.nmt.edu/">About New Mexico Tech</a></div></div><hr><div class="colophon"><address><div class="colophon-author">John W. Shipman</div><div class="colophon-mailto">Comments welcome: <a href="mailto:tcc-doc@nmt.edu">tcc-doc@nmt.edu</a></div></address><div class="colophon-date">Last updated: 2013-12-31 17:59</div><div class="colophon-url">URL: <span class="colophon-uri">http://www.nmt.edu/tcc/help/pubs/tkinter/web/text-methods.html</span></div></div></div></body>
<!-- Mirrored from infohost.nmt.edu/tcc/help/pubs/tkinter/web/text-methods.html by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 06 Nov 2017 11:41:53 GMT -->
</html>
